package com.pxl.springbootinit.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pxl.springbootinit.common.BaseResponse;
import com.pxl.springbootinit.common.ResultUtils;
import com.pxl.springbootinit.model.dto.message.ChatMessageForm;
import com.pxl.springbootinit.model.entity.ChatMessage;
import com.pxl.springbootinit.model.vo.UserVO;
import com.pxl.springbootinit.service.ChatMessageService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

/**
 * 聊天记录接口
 *
 * @author MADAO
 * @create 2024 - 12 - 20 18:04
 */
@Slf4j
@RestController
@RequestMapping("/chat")
public class ChatMessageController {
    @Resource
    private ChatMessageService chatMessageService;

    @GetMapping("/page")
    public BaseResponse<Page<ChatMessage>> pageMessage(ChatMessageForm chatMessageForm){
        return ResultUtils.success(chatMessageService.pageMessage(chatMessageForm));
    }

    @GetMapping("/list")
    public BaseResponse<List<ChatMessage>> listMessage(ChatMessageForm chatMessageForm){
        return ResultUtils.success(chatMessageService.listMessage(chatMessageForm));
    }

    @GetMapping("/user/list/{userId}")
    public BaseResponse<List<UserVO>> listChatWithUser(@PathVariable Long userId){
        return ResultUtils.success(chatMessageService.listChatWithUser(userId));
    }
}
